class UsersController < ApplicationController
    layout "default"
    include OpenAccount::OpenAccountController

    # GET /users/1
    # GET /users/1.xml
    def show
        @user = User.find(params[:id])

        respond_to do |format|
            format.html # show.html.erb
            format.xml  { render :xml => @user }
        end
    end

    def create
        if creating_open_id?
            # do username validation
            if User.find_by_login(params[:openid_user_name])
                flash[:notice] = "The username you selected is already in use.  Please select a different one."
                render :action => 'new'
            else
                key = 'abc'
                user_name = params[:openid_user_name]
                api_sig = OpenID::Util.to_base64(OpenID::Util.hmac_sha1(key, user_name))
                #api_sig =  'a2458f440b556acfe1e7e5e067ccad5f45279085'
                sign_up_url = 'https://www.myopenid.com/api_affiliate_signup?user_name=' + user_name + '.gistr.com&affiliate_id=785&api_sig=' + api_sig
                redirect_to(sign_up_url)
            end
        else
            begin
                @user = User.new(params[:user])
                @user.save!
                self.current_user = @user
                current_user.activate # for now activate all users by default
                redirect_back_or_default('/')
                flash[:notice] = "Thanks for signing up!"
            rescue ActiveRecord::RecordInvalid
                render :action => 'new'
            end
        end
    end
end
